package DataStructure.graph;

import DataStructure.linear.Stack;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class DepthFirstPathsTest {
    public static void main(String[] args) throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(DepthFirstPathsTest.class.getClassLoader().getResourceAsStream("road_find.txt")));
        int total = Integer.parseInt(br.readLine());
        Graph G = new Graph(total);
        int edgeNumber = Integer.parseInt(br.readLine());
        for (int i = 1; i <= edgeNumber; i++) {
            String edge = br.readLine();
            String[] str = edge.split(" ");
            int v = Integer.parseInt(str[0]);
            int w = Integer.parseInt(str[1]);
            G.addEdge(v,w);
        }

        //构建路径查找对象起点为0
        DepthFirstPaths paths = new DepthFirstPaths(G, 0);
        Stack<Integer> path = paths.pathTo(4);
        //遍历stack
        StringBuilder sb = new StringBuilder();
        for (Integer v : path) {
            sb.append(v+"-");
        }
        sb.deleteCharAt(sb.length()-1);
        System.out.println(sb);

    }
}
